﻿@inherits System.Web.Mvc.WebViewPage<Pikapika.Models.ViewModels.Novel.NovelListModel>

@{
    var publisherName = Model.Publisher != null ? Model.Publisher.Name : "全部小说";
	ViewBag.Title = publisherName;
    ViewBag.BodyClassName = "hide-sidebar";
	int thumbnailWidth = 80, thumbnailHeight = 110;
}

@{/*
<div class="list-title">
	@(Model.Publisher != null ? Model.Publisher.Name : "全部")小说列表
</div>
*/}

<ul class="novel-list">
	@foreach (var novelItem in Model.Novels) {
		<li class="novel-list-item">
			<a class="novel-image" href='@Url.UrlForModel(novelItem.Novel)'>
				@if (String.IsNullOrWhiteSpace(novelItem.Novel.ImageUrl)) {
					<span class="novel-image-placeholder"></span>
				} else {
                    @Html.ThumbnailImage(novelItem.Novel.ImageUrl, thumbnailWidth, thumbnailHeight);
				}
			</a>
			<div class="novel-info-box">
				<h2 class="novel-name">@Html.ActionLinkForModel(novelItem.Novel,
											new RouteValueDictionary 
                                                { {"class", "novel-name-link"} })</h2>
				<div class="novel-basic-info">
					<div class="novel-update-time">
						@novelItem.TimeZoneCorrectedUpdatedDate.ToString("yyyy-MM-dd HH:mm")
						更新
					</div>
					<div class="novel-author">
						作者
						@novelItem.Novel.Author
					</div>
					<div class="novel-hit-count">
						点击
						@novelItem.HitCount
					</div>
					<div class="novel-annotation-count">
						吐槽
						@novelItem.AnnotationCount
					</div>
				</div>
				@if (novelItem.LatestChapter != null) {
					<h3 class="novel-latest-chapter">
						最新章节：
						@Html.ActionLinkForModel(novelItem.LatestChapter,
                                        String.Format("{0} {1}", novelItem.LatestVolume.Name, novelItem.LatestChapter.Name),
										new RouteValueDictionary { {"class", "novel-latest-chapter-link"} },
                                        novelItem.Novel,
                                        novelItem.LatestVolume)
					</h3>
				}
				<div class="novel-description" title="@novelItem.Novel.Description">
					@novelItem.Novel.Description
				</div>
			</div>
		</li>
	}
</ul>

<div class="page-navigation">
	@if (Model.PageCount > 1) {
		<text>
			@{
				var publisherId = Model.Publisher != null ? Model.Publisher.Id : 0;
			}
			@if (Model.CurrentPage > 1) {
				<text>
					@Html.ActionLink("首页", "List", new RouteValueDictionary 
                                                        { {"id", publisherId}, 
                                                          {"publisher", publisherName},
                                                          {"page", 1} })
					@Html.ActionLink("上一页", "List", new RouteValueDictionary 
                                                        { {"id", publisherId}, 
                                                          {"publisher", publisherName},
                                                          {"page", Model.CurrentPage - 1} }) 
				</text>
			}
		
			@for (var i = Math.Max(1, Model.CurrentPage - 5); i <= Math.Min(Model.PageCount, Model.CurrentPage + 5); i++) { //>
				<text>
					@if (i == Model.CurrentPage) {
						<text>@i</text>
					} else {
						@Html.ActionLink(String.Format("[{0}]", i), "List", new RouteValueDictionary 
                                                        { {"id", publisherId}, 
                                                          {"publisher", publisherName},
                                                          {"page", i} })
					}
				</text>
			}
		
			@if (Model.CurrentPage < Model.PageCount) {
				<text>
					@Html.ActionLink("下一页", "List", new RouteValueDictionary 
                                                        { {"id", publisherId}, 
                                                          {"publisher", publisherName},
                                                          {"page", Model.CurrentPage + 1} })
					@Html.ActionLink("末页", "List", new RouteValueDictionary 
                                                        { {"id", publisherId}, 
                                                          {"publisher", publisherName},
                                                          {"page", Model.PageCount} })
				</text>
			}
			&nbsp;
			<select onchange="location.href=this.options[this.selectedIndex].value;">
				@for (var i = 1; i <= Model.PageCount; i++) {
					<option value='@Url.Action("List", new RouteValueDictionary 
                                                           { {"id", publisherId}, 
                                                             {"publisher", publisherName}, 
                                                             {"page", i} })'
						@if (i == Model.CurrentPage) {
							<text>selected="true"</text>
						}
						>
						@i
					</option>
				}
			</select>
		</text>
	}
</div>

@section Head {
	@Html.Css("Novel/List.css?20101019")
    @Html.Css("Novel/ListMobile.css", (string)ViewBag.MobileMediaSelector)
	@Html.Script(StandardLibraries.Jquery)
	@Html.Script("jquery.ellipsisText.js")
	<script type="text/javascript">
		//<![CDATA[
			$(function () {
				$(".novel-description").ellipsisText();
				var token;
				$(window).resize(function () {
					if (!token) {
						token = setTimeout(function () {
							$(".novel-description").ellipsisText();
							token = null;
						}, 100);
					};
				});
			});
		//]]>
	</script>
}